// pages/Tabbar/Home/Home.js
import { throttle } from '../../../utils/util';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      console.log(this.getTabBar().data,'this.getTabBar()')
      this.getTabBar().setData({
        active: 0
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log(this.data.activeIndex,'activeIndex')
    if(this.data.activeIndex == 0){
      let child = this.selectComponent('.airPackage');
      child.onRefresh();
    }
    if(this.data.activeIndex == 1){
      let child = this.selectComponent('.hotelPackage');
      child.onRefresh();
    }
    if(this.data.activeIndex == 2){
      let child = this.selectComponent('.luxuryCarPackage');
      child.onRefresh();
    }
    if(this.data.activeIndex == 3){
      let child = this.selectComponent('.yachtPackage');
      child.onRefresh();
    }
    if(this.data.activeIndex == 4){
      let child = this.selectComponent('.sportsPackage');
      child.onRefresh();
    }
    setTimeout(()=>{
      wx.stopPullDownRefresh({
        success: (res) => {
          console.log(res,'刷新成功')
          wx.showToast({
            title: '刷新成功',
            icon: 'none',
          })
        },
      })
    },1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: throttle(function(){
    console.log('上拉加载')
    if(this.data.activeIndex == 0){
      let child = this.selectComponent('.airPackage');
      child.onLoadMore();
    }
    if(this.data.activeIndex == 1){
      let child = this.selectComponent('.hotelPackage');
      child.onLoadMore();
    }
    if(this.data.activeIndex == 2){
      let child = this.selectComponent('.luxuryCarPackage');
      child.onLoadMore();
    }
    if(this.data.activeIndex == 3){
      let child = this.selectComponent('.yachtPackage');
      child.onLoadMore();
    }
    if(this.data.activeIndex == 4){
      let child = this.selectComponent('.sportsPackage');
      child.onLoadMore();
    }
  },500),

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  // 切换分类项目
  tabChange(e){
    console.log(e.detail,'e')
    this.setData({activeIndex: e.detail});
  },
})